﻿using System.Net;
using System.Threading.Tasks;
using JTTD.Common.Attribute;
using JTTD.Domain;
using JTTD.Domain.Dtos;
using JTTD.Domain.Dtos.ShopCoupon.Request;
using JTTD.Domain.Dtos.ShopCoupon.Response;
using JTTD.Domain.IService;
using Microsoft.AspNetCore.Mvc;

namespace JTTD.Controllers
{
    /// <summary>
    /// 店铺优惠券
    /// </summary>
    [Route("api/shopCoupons")]
    [ApiController]
    public class ShopCouponController : BaseController
    {
        private readonly IShopCouponService _shopCouponService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="shopCouponService"></param>
        public ShopCouponController(IShopCouponService shopCouponService)
        {
            _shopCouponService = shopCouponService;
        }

        /// <summary>
        /// 分页获取用户领取当前店铺的所有店铺优惠券(店家管理后台)
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<PageResult<ShopCouponResponseDto>>))]
        [UserRoot(UserType = Common.Enum.UserTypeEnum.Shop)]
        public async Task<IActionResult> GetCouponPageList([FromQuery]ShopCouponSearchByShopRequestDto dto)
        {
            var result = await _shopCouponService.GetShopCouponPageListByShop(UserId, dto);
            return Ok(result);
        }

        /// <summary>
        /// 分页获取指定用户能使用的店铺优惠券(微信公众号)
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("myShopCoupons")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<PageResult<ShopCouponResponseDto>>))]
        [UserRoot(UserType = Common.Enum.UserTypeEnum.Ordinary)]
        public async Task<IActionResult> GetCouponPageList([FromQuery]ShopCouponSearchRequestDto dto)
        {
            var result = await _shopCouponService.GetShopCouponPageList(UserId, dto);
            return Ok(result);
        }



        /// <summary>
        /// 店铺优惠券核销
        /// </summary>
        /// <param name="no">优惠券号</param>
        /// <returns></returns>
        [HttpPut]
        [Route("{no}")]
        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(ApiResult<bool>))]
        [UserRoot(UserType = Common.Enum.UserTypeEnum.Shop)]
        public async Task<IActionResult> ChangeShopCoupon([FromRoute]string no)
        {
            var result = await _shopCouponService.ChangeShopCoupon(no);
            return Ok(result);
        }



    }
}